package net.tv90.volunteerserveradmin.dao;

import io.lettuce.core.dynamic.annotation.Param;
import net.tv90.volunteerserveradmin.model.domain.Image;
import net.tv90.volunteerserveradmin.model.domain.VolunteerProjectRelation;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface VolunteerProjectRelationRepository extends JpaRepository<VolunteerProjectRelation, Long>, JpaSpecificationExecutor<VolunteerProjectRelation> {
    // 根据学生ID和项目ID查询是否存在该关系
    boolean existsByVolunteerIdAndProjectId(Long volunteerId, Long projectId);

    // 可以根据志愿者ID和项目ID查询具体的关联记录
    VolunteerProjectRelation findByVolunteerIdAndProjectId(Long volunteerId, Long projectId);

    Long countByProjectId(Long projectId);

    @Query("SELECT v.volunteerId FROM VolunteerProjectRelation v WHERE v.projectId = :projectId")
    List<Long> findVolunteerIdsByProjectId(@Param("projectId") Long projectId);

    @Query("SELECT v.projectId FROM VolunteerProjectRelation v WHERE v.volunteerId = :studentId")
    List<Long> findProjectIdsByVolunteerId(@Param("studentId") Long studentId);

}
